
from .controller.gitlabPipelinesController import pipelinesProject

from .controller.gitlabProjectsController import getListProjects
from .controller.gitlabPipelinesJobsController import pipelineJobsProjects
from .controller.gitlabConnController import gitlalConn
from django.views import View
from django.http.response import HttpResponse, JsonResponse

from .controller.gitlabTriggerScheduleController import pipelineTrigger, pipelineSchedule

from .controller.gitlabConnController import gitlalConn

id = 34


class piplines(View):
  @staticmethod
  def get(request):
    project = gitlalConn.gl.projects.get(id)
    piplinesIdAll = pipelinesProject.piplinesList(project)
    return HttpResponse(piplinesIdAll)


class pipelineTriggers(View):
    @staticmethod
    def get(request):
      # get a project id
        project = gitlalConn.gl.projects.get(id)
      # obtain project description
        triggers = pipelineTrigger.getTrigger(project)

        return HttpResponse(triggers)

    @staticmethod
    def post(request):
        # get a project id
        project = gitlalConn.gl.projects.get(34)
        triggersDecription = 'test_trigger_id'
        # create trigger
        trigger = pipelineTrigger.createTrigger(project, triggersDecription)

        return HttpResponse(trigger)


class pipelineRunTriggers(View):
    @staticmethod
    def post(request):
        project = gitlalConn.gl.projects.get(34)
        triggersDecription = 'test_trigger_id'
        # run oen project trigger
        runTrigger = pipelineTrigger.runTriggerPipeline(
            project, triggersDecription)

        return HttpResponse(runTrigger)


class pipelineSchedules(View):
    @staticmethod
    def get(request):
        project = gitlalConn.gl.projects.get(34)
        schedules = pipelineSchedule.getSchedules(project)
        return HttpResponse(schedules)

    @staticmethod
    def post(request):

        project = gitlalConn.gl.projects.get(34)
        scheduledescription = 'dailxay build'

        createSchedule = pipelineSchedule.createSchedules(
            project, scheduledescription)

        return HttpResponse(createSchedule)


class pipelineProjecs(View):
    @staticmethod
    def get(request):
        pipelineid = 11
        pipelineID = pipelineid or {}

    def post(request):
        pass


class pipelineJobs(View):
    @staticmethod
    def get(request):
        project = gitlalConn.gl.projects.get(34)
        # jobid = 101
        jobsList = pipelineJobsProjects.jobsList(project)

        # print(pipelineJobsProjects.jobsOneSingle(project, jobid))
        # a = pipelineJobsProjects.jobsPaly(project, jobid)
        return JsonResponse(jobsList,safe=False)


class projectsList(View):
    @staticmethod
    def get(request):
        projectsList = getListProjects.allProjectLists()


        return JsonResponse(projectsList,safe=False)
